<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 当我们想要劫持多个属性的时候  可以封装成一个函数
    let object = {
        name:'刘德华',
        age:40,
        hubby:'唱歌'
    }
    function changeItem(object){
        function desc(value){
         return {
            get:function(){
              console.log('我是get方法');
              return value
            },
            set:function(newvalue){
                console.log(newvalue);
                console.log('我是set方法');
                value = newvalue

            }
         } 
        }
        for(var i in object){
            Object.defineProperty(object,i,desc(object[i]))
        }

    }
    changeItem(object)
 
    object.name = '刘德华爱唱歌'
    object.age = 50
    object.hubby = '演戏'

    console.log(object.name);
    console.log(object.age);
    console.log(object.hubby);
</script>
</html>